﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SharpSNS.Auth
{
    /// <summary>
    /// Encapsulates the response from a startOSCARSession API call
    /// </summary>
    public class StartOscarSessionResponse : ApiResponse
    {
        private string _BossHost;
        /// <summary>
        /// BOSS host to connect to
        /// </summary>
        public string BOSSHost
        {
            get { return _BossHost; }
        }

        private int _BossPort;
        /// <summary>
        /// BOSS port to connect to
        /// </summary>
        public int BOSSPort
        {
            get { return _BossPort; }
        }

        private byte[] _BossCookie;
        /// <summary>
        /// BOSS authorization cookie byte array
        /// </summary>
        public byte[] BOSSCookie
        {
            get { return _BossCookie; }
        }

        /// <summary>
        /// Initializes the StartOscarSessionResponse object
        /// </summary>
        /// <param name="respNode">XmlNode containing the response data</param>
        public StartOscarSessionResponse(XmlNode respNode)
            : base(respNode)
        {
            if (ResponseCode == ApiResponseCode.Success)
            {
                XmlNode dataNode = respNode["data"];
                _BossHost = dataNode["host"].InnerText;
                _BossPort = int.Parse(dataNode["port"].InnerText);
                _BossCookie = Convert.FromBase64String(dataNode["cookie"].InnerText);
            }
        }
    }
}
